package com.banhujiu.common.utils;

import java.util.Collection;
import java.util.function.Function;

/**
 * @author banhujiu
 * @date 2017/12/3 0003 20:28
 */
public class ObjectsUtils {
	/**
	 * check Object is empty
	 *
	 * @param t source
	 *
	 * @return is empty (true or false)
	 */
	public static boolean isEmpty(Object t) {
		if (t == null) {
			return true;
		}
		if (t instanceof String && "".equals(t)) {
			return true;
		}
		if (t instanceof Collection && ((Collection) t).isEmpty()) {
			return true;
		}
		return false;
	}

	/**
	 * check object is empty
	 *
	 * @param t        source object
	 * @param function a function for t to check t is empty
	 * @param <T>      source object type
	 *
	 * @return is empty (true or false)
	 */
	public static <T> boolean isEmpty(T t, Function<T, Boolean> function) {
		if (isEmpty(t) || function.apply(t)) {
			return true;
		}
		return false;
	}
}
